use std::fs;
use std::path::Path;
use std::process::Command;

//批量文件处理
struct BatchProcessor {
    input_dir: String,
    output_dir: String,
}
impl BatchProcessor {
    fn new(input_dir: &str, output_dir: &str) -> BatchProcessor {
        Self {
            input_dir: input_dir.to_string(),
            output_dir: output_dir.to_string(),
        }
    }
    fn process_file(&self) -> Result<(), Box<dyn std::error::Error>> {
        for entry in fs::read_dir(&self.input_dir)?{
            let entry = entry?;
            let path = entry.path();

            if path.is_file() {
                let output_path = Path::new(&self.output_dir)
                    .join(path.file_name().unwrap());
                Command::new("cp")
                    .arg(path)
                    .arg(&output_path)
                    .status()?;
            }
        }
        Ok(())
    }
}
fn main() {
    let cp_dir = BatchProcessor::new("/tmp/abc", "./tmp");
    cp_dir.process_file().unwrap();
}
